﻿
/**
 * Written by :
 * @author Floz
 * www.floz.fr || www.minuit4.fr
 */
package fr.tilzy.core.flags 
{
	
	public class Flag
	{
		
		// - PRIVATE VARIABLES -----------------------------------------------------------
		
		private static const LIST:/*Flag*/Array = [];
		
		// - PUBLIC VARIABLES ------------------------------------------------------------
		
		public static const NONE:Flag = new Flag( 0x000000, "none" );
		public static const WALKABLE:Flag = new Flag( 0x000001, "walkable" );
		
		public var value:int;
		public var name:String;
		
		// - CONSTRUCTOR ----------------------------------------------------------------- 
		
		public function Flag( value:int, name:String ) 
		{
			this.value = value;
			this.name = name;
			
			LIST[ LIST.length ] = this;
		}
		
		// - EVENTS HANDLERS -------------------------------------------------------------
		
		// - PRIVATE METHODS -------------------------------------------------------------
		
		// - PUBLIC METHODS --------------------------------------------------------------
		
		public static function getByValue( value:int ):Flag
		{
			var i:int = LIST.length;
			while ( --i > -1 )
				if ( LIST[ i ].value == value ) return LIST[ i ];
			
			return null;
		}
		
		public static function getByName( name:String ):Flag
		{
			var i:int = LIST.length;
			while ( --i > -1 )
				if ( LIST[ i ].name == name ) return LIST[ i ];
			
			return null;
		}
		
		public function valueOf():int
		{
			return value;
		}
		
		public function toString():String
		{
			return name;
		}
		
		// - GETTERS & SETTERS -----------------------------------------------------------
		
	}
	
}